﻿(function ($) {
    var dialogOpusMessageSettings = {
        'width': 200,
        'title': 'Opus Suite',
        'resizable': true,
        'position': [($(window).size.width / 2) / 245, 10],
        message: null,
        btnOK: true,
        btnCancel: false
    };

    var methods = {
        show: function (options) {
            if (options) {
                $.extend(dialogOpusMessageSettings, options);
            }

            //return this.each(function () {
            var d = $(this).dialog({
                autoOpen: true,
                width: dialogOpusMessageSettings.width,
                position: dialogOpusMessageSettings.position,
                resizable: dialogOpusMessageSettings.resizable,
                title: dialogOpusMessageSettings.title,
                modal: true,
                open: function (event, ui) {
                    $(this).load('/Shared/OpusMessageDialog', {
                        message: dialogOpusMessageSettings.message,
                        btnOK: dialogOpusMessageSettings.btnOK,
                        btnCancel: dialogOpusMessageSettings.btnCancel
                    });
                },
                buttons: {
                    "OK": function () {
                        $(this).dialog("close");
                    },
                    "Cancel": function () {
                        $(this).dialog("close");
                    }
                }
            });

            return this;
        }
    };

    $.fn.opusMessage = function (method) {
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || !method) {
            return methods.show.apply(this, arguments);
        } else {
            $.error('Method ' + method + ' does not exist on jQuery.opusMessage');
        }
    };
})(jQuery);
